feat: add Object::GetPrototype and Object::SetPrototype#1715
feat: add Object::GetPrototype and Object::SetPrototype#1715KevinEady wants to merge 1 commit intonodejs:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1715 +/- ##
=======================================
Coverage 63.50% 63.51%
=======================================
Files 3 3
Lines 2047 2050 +3
Branches 728 729 +1
=======================================
+ Hits 1300 1302 +2
Misses 162 162
- Partials 585 586 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| ### GetPrototype() | ||
|
|
||
| ```cpp | ||
| Napi::Object Napi::Object::GetPrototype() const; |
There was a problem hiding this comment.
The prototype of the method is MaybeOrValue<Object> Object::GetPrototype() const.
Maybe it could be good to explain if the object has no prototype.
There was a problem hiding this comment.
Hi @NickNaso ! 😄
If the object has no prototype (i.e. a null prototype), the Maybe would have a value of null, which is a valid Value-having Maybe.
If using NODE_ADDON_API_ENABLE_MAYBE:
- Passing
nullorundefinedtoObject::GetPrototype(), then the Maybe's value is Nothing.
If not using NODE_ADDON_API_ENABLE_MAYBE:
- Passing
nullorundefinedtoGetPrototypewill throw aTypeError: Cannot convert undefined or null to object.
I'm not sure if this needs to be specifically documented, as this is just how Maybes work?
| const prototype = {}; | ||
| const obj = Object.create(prototype); | ||
| assert.strictEqual(binding.object.getPrototype(obj), prototype); | ||
| } |
There was a problem hiding this comment.
Could be useful to test when the oblect has no prototype const obj = Object.create(null); ?
There was a problem hiding this comment.
aa0f8c0 to
db1379a
Compare
Object::GetPrototypeandObject::SetPrototypeFixes: #1691